<?php

$key = include "./lib/key.php";

$param = $_POST;
$rsa = new \lib\RSA();
$res = "";
switch ($param["type"]) {
    case "encrypt":
        $res = $rsa->encrypt($param["data"],$key["serverPublicKey"]);
        break;
    case "decrypt":
        $res = $rsa->decrypt($param["data"],$key["serverPrivateKey"]);
        break;
    case "sign":
        $res = $rsa->sign($param["data"],$key["serverPrivateKey"]);
        break;
    case "signVerify":
        $res = $rsa->signVerify($param["data"],$param["sign"],$key["serverPublicKey"]);
        break;
    case "signByServerPrivateKey":
        $res = $rsa->sign($param["data"],$key["serverPrivateKey"]);
        break;
    case "signVerifyByClientPublicKey":
        $res = $rsa->signVerify($param["data"],$param["sign"],$key["clientPublicKey"]);
        break;
    case "encryptByClientPrivateKey":
        $res = $rsa->encrypt($param["data"],$key["clientPublicKey"]);
        break;
    case "decryptByServerPrivateKey":
        $res = $rsa->decrypt($param["data"],$key["serverPrivateKey"]);
        break;
}

response($res);